function add(arg1, arg2) {
  let t1 = 0;
  let t2 = 0;
  if (arg1.toString().indexOf('.') > -1) {
    //第一个小数的位数
    t1 = arg1.toString().split('.')[1].length;
  }
  if (arg2.toString().indexOf('.') > -1) {
    t2 = arg2.toString().split('.')[1].length;
  }
  //取得最长小数的10的指数
  let m = Math.pow(10, Math.max(t1, t2))
  let res = (arg1 * m + arg2 * m) / m
  return res
}

function mul(arg1, arg2) {
  let t1 = arg1.toString()
  let t2 = arg2.toString()
  let m = 0;
  if (t1.indexOf('.') > -1) {
    m += t1.split('.')[1].length;
  }
  if (t2.indexOf('.') > -1) {
    m += t2.split('.')[1].length;
  }
  return Number(t1.replace('.', '')) * Number(t2.replace('.', '')) / Math.pow(10, m)
}

function sub(arg1, arg2) {
  let t1 = 0;
  let t2 = 0;
  if (arg1.toString().indexOf('.') > -1) {
    t1 = arg1.toString().split('.')[1].length
  }
  if (arg2.toString().indexOf('.') > -1) {
    t2 = arg2.toString().split('.')[1].length
  }
  let m = Math.pow(10, Math.max(t1, t2))
  let res = (mul(arg1, m) - mul(arg2, m)) / m
  return res;
}

function div(arg1,arg2){
  let t1=0, t2=0;
  let a1 =arg1.toString();
  let a2=arg2.toString();
  if(a1.indexOf('.')>-1){
    t1=a1.split('.')[1].length;
  }
  if(a2.indexOf('.')>-1){
    t2=a2.split('.')[1].length;
  }
  let r1 =Number(a1.replace('.',''))
  let  r2 =Number(a2.replace('.',''))

return   mul(r1/r2,Math.pow(10,t2-t1));
}
module.exports = {
  add,mul,sub,div
}